<template>
	<view class="content poRel" :style="'background: linear-gradient('+theme.ba_color+' 2%, #fff 11%);'">
		<view class="wid100">
			<view class="wid90 mar dis disAl disJuB" style="height: 100rpx;">
				<picker :value="cityIndex" @change="bindCityChange" :range-key="'title'" :range="addressList">
					<view class="dis disAl">
						<view class="mar-right10 foSi25">{{city.title}}</view>
						<image src="../../static/xiala.png" style="width: 14rpx;height: 8rpx;"></image>
					</view>
				</picker>
				<view class="dis disAl borRad40 hei60 bacFFF" style="width: 515rpx;">
					<view class="dis disJuC" style="width: 13%;">
						<uni-icons type="search" size="30rpx" color="#AFB6B1"></uni-icons>
					</view>
					<input class="wid85 foSi25" v-model="sousuo" @input="sousuoInput" 
						placeholder="请输入技师姓名" placeholder-style="color: #AFB6B1;" :focus="focusFlag" :cursor="cursorL"/>
				</view>
			</view>
			<view class="wid90 mar dis disAl disJuB foSi22 fowe600" style="height: 68rpx;">
				<view class="dis disJuC disAl borRad40" 
				:style="xuanze == 0?'background-color: '+theme.main_color+'21;color: '+theme.main_color+';':'background-color: #EBEFEB;'"
					style="padding: 8rpx 22rpx;line-height: 40rpx;" @click="xuan(0)">
					<!-- <image src="../../static/quanbu1.png" style="width: 17rpx;height: 17rpx;"></image> -->
					<uni-icons custom-prefix="iconfont" size="25rpx" type="icon-dangan" :color="xuanze == 0?theme.main_color:'#000'"></uni-icons>
					<view class="mar-left10">全部</view>
				</view>
				<view class="dis disJuC disAl borRad40" 
					:style="xuanze == 1?'background-color: '+theme.main_color+'21;color: '+theme.main_color+';':'background-color: #EBEFEB;'"
					style="padding: 8rpx 22rpx;line-height: 40rpx;" @click="xuan(1)">
					<!-- <image src="../../static/dingwei3.png" style="width: 15rpx;height: 18rpx;"></image> -->
					<uni-icons size="25rpx" type="location-filled" :color="xuanze == 1?theme.main_color:'#000'"></uni-icons>
					<view class="mar-left10">最近距离</view>
				</view>
				<view class="dis disJuC disAl borRad40" 
					:style="xuanze == 2?'background-color: '+theme.main_color+'21;color: '+theme.main_color+';':'background-color: #EBEFEB;'"
					style="padding: 8rpx 22rpx;line-height: 40rpx;" @click="xuan(2)">
					<!-- <image src="../../static/shouchang1.png" style="width: 18rpx;height: 18rpx;"></image> -->
					<uni-icons size="25rpx" type="star-filled" :color="xuanze == 2?theme.main_color:'#000'"></uni-icons>
					<view class="mar-left10">收藏最多</view>
				</view>
				<view class="dis disJuC disAl borRad40" 
					:style="xuanze == 3?'background-color: '+theme.main_color+'21;color: '+theme.main_color+';':'background-color: #EBEFEB;'"
					style="padding: 8rpx 22rpx;line-height: 40rpx;" @click="xuan(3)">
					<!-- <image src="../../static/mianfei1.png" style="width: 22rpx;height: 22rpx;"></image> -->
					<uni-icons custom-prefix="iconfont" size="25rpx" type="icon-freeCharge" :color="xuanze == 3?theme.main_color:'#000'"></uni-icons>
					<view class="mar-left10">免出行费</view>
				</view>
			</view>
		</view>
		<scroll-view style="height: calc(100vh - 168rpx);" class="wid100" scroll-y="true" @scrolltolower="lower">
			<wsj v-if="list.length == 0" zs='0'></wsj>
			<view style="height: 1rpx;"></view>
			<block v-for="(item,index) in list" :key="index">
				<view class="wid90 mar mar-top30 borRad10" @click="tiaozhuan('/pages/technician/particulars?id='+item.id)"
					style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);">
					<view class="wid90 mar" style="padding: 22rpx 0;">
						<view class="dis disAl">
							<view style="width: 30%;">
								<view class="poRel" style="width: 150rpx;height: 208rpx;">
									<image :lazy-load="true" :src="item.coverimg" style="" class="borRad20 wh100" mode="aspectFill"></image>
									<view class="poAbs dis disAl disJuC coFFF xinren foSi18" 
										:style="'background-color: '+theme.main_color+';'">新</view>
								</view>
							</view>
							<view style="width: 70%;">
								<view class="dis disAl disJuB liH40">
									<view class="dis disAl">
										<view class="foSi30 fowe600 mar-right20">{{item.name}}</view>
										<!-- <image src="../../static/renzheng.png" class="mar-right20" style="width: 25rpx;height: 25rpx;"></image> -->
										<uni-icons custom-prefix="iconfont" size="26rpx" :color="theme.main_color"
											type="icon-renzhengpeizhi" class="mar-right20"></uni-icons>
										<view class="dis disAl">
											<image src="../../static/pingjia.png" style="width: 27rpx;height: 24rpx;"></image>
											<view class="mar-left10 foSi25">{{item.star}}</view>
										</view>
									</view>
									<view class="foSi20" style="color: #737373;">已服务{{item.service_order_num}}单</view>
								</view>
								<view class="dis disAl flwa" :style="'color: '+theme.main_color+';'">
									<block v-for="(item1,index1) in 3" :key="index1">
										<view class="borRad10 mar-top15 mar-right10 tim1 foSi18"
											:style="'background-color: '+theme.main_color+'21;'">热情</view>
									</block>
								</view>
								<view class="mar-top20 dis disAl disJuB foSi20" style="color: #737373;">
									<view class="dis disAl">
										<view class="dis disAl">
											<image src="../../static/mendian1.png" style="width: 25rpx;height: 22rpx;"></image>
											<view class="mar-left10">{{item.store_name}}</view>
										</view>
										<view class="dis disAl mar-left30">
											<image src="../../static/liulan1.png" style="width: 26rpx;height: 20rpx;"></image>
											<view class="mar-left10">{{item.see_num}}</view>
										</view>
										<view class="dis disAl mar-left30" @click.stop="shouchang(index)">
											<uni-icons v-if="item.collect == 2" type="star-filled" size="30rpx" :color="theme.main_color"></uni-icons>
											<uni-icons v-if="item.collect == 1" type="star" size="30rpx" color="#737373"></uni-icons>
											<view class="mar-left10">{{item.coll_num}}</view>
										</view>
									</view>
									<view class="dis disAl">
										<uni-icons type="location-filled" size="30rpx" :color="theme.main_color"></uni-icons>
										<view class="foSi25 mar-left10">{{item.km}}</view>
									</view>
								</view>
								<view class="mar-top15 dis disJuB foSi20" style="align-items: flex-end;">
									<view class="dis disAl">
										<!-- <image src="../../static/yuyue1.png" style="width: 25rpx;height: 25rpx;"></image> -->
										<uni-icons custom-prefix="iconfont" size="26rpx" :color="theme.seco_color"
											type="icon-shijianguanli1"></uni-icons>
										<view class="mar-left10 fowe600" :style="'color: '+theme.seco_color+';'">最早可约时间{{item.zztime}}</view>
									</view>
									<view class="dis disAl disJuC coFFF borRad20 butt2"	:style="'background-color: '+theme.main_color+';'">去下单</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</block>
			<view style="height: 100rpx;" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}"></view>
		</scroll-view>
		<tablist :back="theme.main_color" :datalist="datalist" :index="2"></tablist>
		<!-- <unicloud-city-select ref="citySelect" :hot-city="hotCity" :location="false" @select="select"></unicloud-city-select> -->
	</view>
</template>

<script>
	import tablist from "../common/tablist/tablist.vue"
	import wsj from '../common/w_sj.vue'
	export default {
		components: {
			wsj,tablist
		},
		data() {
			return {
				url: this.global.url,
				timer: null,
				sousuo: '',
				last_page: 0,
				page: 1,
				address: '',
				id: '',
				xuanze: 0,
				list: [],
				addressList: [],
				cityIndex: 0,
				// 当前选择的城市
				city: null,
				isInputFocus:true,
				cursorL:0,
				focusFlag: false,
				theme: null,
				datalist: [],
				paddingBottomHeight: 0
			}
		},
		created() {
			let that = this;
			uni.hideTabBar()
			uni.getSystemInfo({
				success: function (res) {
					let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
					model.forEach(item => {
						//适配iphoneX以上的底部，给tabbar一定高度的padding-bottom
						if(res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
							that.paddingBottomHeight = 40;
						}
					})
				}
			});
		},
		onLoad(option) {
			this.datalist = uni.getStorageSync('bom')
			this.addressList = uni.getStorageSync('address');
			this.theme = uni.getStorageSync('theme')
			uni.setNavigationBarColor({
				frontColor: '#000000',
				backgroundColor: this.theme.ba_color,//底部背景色
			})
		},
		onShow() {
			this.city = uni.getStorageSync('city');
			this.getList()
		},
		methods: {
			shouchang(index){
				var that = this;
				if(!uni.getStorageSync('token')){
					return uni.showToast({title: '请登录',icon: 'error',duration: 2000}) 
				}
				var type = that.list[index].collect == 1?2:1
				uni.request({
					url: that.global.url + 'api/qianyu_smfw/trends/collect_add',
					method: "POST",
					header: {
						'site-id': that.global.site_id,//自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						tech_id: that.list[index].id,
						type: that.list[index].collect
					},
					success(res) {
						let result = res.data
						if (result.code == 1) {
							that.list[index].collect = type
							if(type == 2){
								that.list[index].coll_num += 1
							}else{
								that.list[index].coll_num -= 1
							}
						}else{
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							}) 
						}
					}
				})
			},
			bindCityChange: function(e) {
				this.cityIndex = e.detail.value
				this.city = this.addressList[this.cityIndex]
				uni.setStorageSync('city', this.addressList[this.cityIndex])
				this.page = 1
				this.getList()
			},
			xuan(index){
				if(this.xuanze != index){
					this.xuanze = index
					this.page = 1
					this.getList()
				}
			},
			sousuoInput: function(event) {
				var that = this
				if (that.timer !== null) clearTimeout(that.timer)
				that.timer = setTimeout(() => {
					that.sousuo = event.target.value
					that.page = 1
					that.getList()
					console.log(that.sousuo)
				}, 1000)
			},
			getList(){
				var that = this;
				uni.request({
					url: that.global.url + 'api/qianyu_smfw/technician/lists',
					method: "POST",
					header: {
						'site-id': that.global.site_id ,//自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						city: that.city.id,
						name: that.sousuo,
						lon: uni.getStorageSync('lon')?uni.getStorageSync('lon'):125.35043,
						lat: uni.getStorageSync('lat')?uni.getStorageSync('lat'):43.86414,
						status: that.xuanze,
						page: that.page
					},
					success(res) {
						let result = res.data
						if (result.code == 1) {
							that.last_page = result.data.last_page
							if(that.page == 1){
								that.list = result.data.data
							}else{
								that.list = that.list.concat(result.data.data)
							}
						}else{
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							}) 
						}
					}
				})
			},
			lower(e) {
				if(this.last_page > this.page){
					this.page++
					this.getList()
				}
			},
			fanhui(){
				uni.navigateBack(1)
			},
			tiaozhuan(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.content {
		min-height: 100vh;
	}
	.tim1{
		padding: 6rpx 13rpx;
	}
	.butt2{
		width: 135rpx;
		height: 55rpx;
		border-radius: 10rpx;
	}
	.richImg {
	    width: 100% !important;
	    height: auto !important;
	}
	.xinren{
		border-radius: 0rpx 16rpx 0rpx 10rpx;
		width: 29rpx;
		height: 32rpx;
		top: 0;
		right: 0;
	}
</style>
